package cn.yuemouren.queue;

import cn.yuemouren.array.Array;

/**
 * @Author: Timi
 * @Description: 数组实现队列
 * @Date: 2020/5/11 15:33
 */
public class ArrayQueue<T> implements Queue<T>{

    private Array<T> queue;

    public ArrayQueue() {
        this.queue = new Array<>();
    }

    public ArrayQueue(int capacity) {
        this.queue = new Array<>(capacity);
    }

    @Override
    public void enQueue(T t) {
        queue.addLast(t);
    }

    @Override
    public T dnQueue() {
        return queue.removeFirst();
    }

    @Override
    public T getHead() {
        return queue.getFirst();
    }

    @Override
    public int getSize() {
        return queue.getSize();
    }

    public int getCaptity() {
        return queue.getCapacity();
    }

    @Override
    public boolean isEmpty() {
        return queue.isEmpty();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("ArrayQueue: [");
        for (int i = 0; i < queue.getSize(); i++){
            sb.append(queue.get(i));
            if(i != queue.getSize()-1){
                sb.append(", ");
            }
        }
        sb.append("] tail");
        return sb.toString();
    }
}
